<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Home\Controller;

use Think\Model;

header('content-type:text/html;charset=utf8');

class HelperController extends HomeController
{
	public function _initialize()
	{
		if (ACTION_NAME != 'login' && !session('uid')) {
			header('Location:' . U('login'));
		}
	}

	/**
	 * 登录
	 * */
	public function login()
	{
		session('uid', 5);
		session('iid', 1);

		$this->assign('title', '登录');
		$this->assign('is_menu', true);
		$this->display();
	}

	/**
	 * 首页
	 * */
	public function index()
	{
		$this->assign('title', '首页');
		$this->assign('is_menu', true);
		$this->display();
	}

	/**
	 * 找课
	 * */
	public function course()
	{
		$this->assign('title', '登录');
		$this->assign('is_menu', true);
		$this->display();
	}

	/**
	 * 学习中心
	 * */
	public function study()
	{
		$this->assign('title', '学习中心');
		$this->assign('is_menu', true);
		$this->display();
	}

	/**
	 * 我的
	 * */
	public function my()
	{
		$uid = session('uid');

		$param['uid'] = $uid;

		$data = sendApi('Apis/userCenter', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '我的');
		$this->assign('is_menu', true);
		$this->display();
	}

	/**
	 * 设置
	 * */
	public function my_set()
	{
		$this->assign('title', '设置');
		$this->display();
	}

	/**
	 * 我的收藏
	 * */
	public function my_wdsc()
	{
		$input = I('post.');

		$uid = session('uid');
		$type = 1;
		$page = $input['page'];
		$pagesize = $input['pagesize'];

		$param['uid'] = $uid;
		$param['type'] = $type;
		$param['page'] = $page;
		$param['pagesize'] = $pagesize;

		$data = sendApi('Apis/videoCollectList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);
		$this->assign('activeIndex', 0);

		$this->assign('title', '我的收藏');
		$this->display();
	}

	/**
	 * 购物车
	 * */
	public function my_gwc()
	{
		$uid = session('uid');

		$param['uid'] = $uid;

		$data = sendApi('Apis/goodsCarList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '购物车');
		$this->display();
	}

	/**
	 * 我的卡包
	 * */
	public function my_wdkb()
	{
		$input = I('post.');

		$uid = session('uid');
		$status = -1;
		$page = $input['page'];
		$pagesize = $input['pagesize'];

		$param['uid'] = $uid;
		$param['status'] = $status;
		$param['page'] = $page;
		$param['pagesize'] = $pagesize;

		$data = sendApi('Apis/userCoupon', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);
		$this->assign('activeIndex', 0);

		$this->assign('title', '我的卡包');
		$this->display();
	}

	/**
	 * 推广赚钱
	 * */
	public function my_tgzq()
	{
		$input = I('post.');

		$uid = session('uid');
		$page = $input['page'];
		$pagesize = $input['pagesize'];

		$param['uid'] = $uid;
		$param['page'] = $page;
		$param['pagesize'] = $pagesize;

		$data = sendApi('Apis/userProfitList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '推广赚钱');
		$this->display();
	}

	/**
	 * 提现
	 * */
	public function my_tgzq_tx()
	{
		$uid = session('uid');

		$param['uid'] = $uid;

		$data = sendApi('Apis/withdrawPageData', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '提现');
		$this->display();
	}

	/**
	 * 我要加盟
	 * */
	public function my_wyjm()
	{
		$uid = session('uid');

		$param['uid'] = $uid;

		$data = sendApi('Apis/institutionInfo', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '我要加盟');
		$this->display();
	}

	/**
	 * 收货地址
	 * */
	public function my_add()
	{
		$uid = session('uid');

		$param['uid'] = $uid;

		$data = sendApi('Apis/addressList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '收货地址');
		$this->display();
	}

	/**
	 * 新增收货地址
	 * */
	public function my_add_xz()
	{
		$id = $_GET['id'];

		if ($id) {
			$param['id'] = $id;

			$data = sendApi('Apis/addressDetail', $param);

			$data = json_decode($data, true);
			$data = $data['data'];
			$data['is_default'] = $data['is_default'] == 1 ? '是' : '否';

			$data['region_desc'] = $data['region'][0] . ' ' . $data['region'][1] . ' ' . $data['region'][2];
			$this->assign('data', $data);

			$this->assign('data_json', json_encode($data));

			$this->assign('title', '编辑收货地址');
		} else {
			$this->assign('title', '新增收货地址');
		}

		$this->display();
	}

	/**
	 * 我的消息
	 * */
	public function my_wdxx_xt()
	{
		$uid = session('uid');
		$type = $_GET['type'] ? $_GET['type'] : 0;

		$param['uid'] = $uid;
		$param['type'] = $type;

		$data = sendApi('Apis/msgList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);
		$this->assign('activeIndex', 0);

		$this->assign('title', '我的消息');
		$this->display();
	}

	/**
	 * 系统消息详情
	 * */
	public function my_msg_page()
	{
		$id = $_GET['id'];
		$uid = session('uid');
		$status = $_GET['status'];

		$param['id'] = $id;
		$param['uid'] = $uid;
		$param['status'] = $status;

		$data = sendApi('Apis/msgDetail', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '消息详情');
		$this->display();
	}

	/**
	 * 新闻资讯
	 * */
	public function my_news()
	{
		$type_id = $_GET['type_id'] ? $_GET['type_id'] : 0;

		$param['type_id'] = $type_id;

		$data = sendApi('Apis/informationList', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);
		$this->assign('activeIndex', 0);

		$this->assign('title', '新闻资讯');
		$this->display();
	}

	/**
	 * 资讯详情
	 * */
	public function my_news_page()
	{
		$id = $_GET['id'];

		$param['id'] = $id;

		$data = sendApi('Apis/informationDetail', $param);
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '新闻资讯');
		$this->display();
	}

	/**
	 * 意见反馈
	 * */
	public function my_yjfk()
	{
		$data = sendApi('Apis/feedbackType');
		$this->assign('data_json', $data);
		$this->assign('data', json_decode($data, true)['data']);

		$this->assign('title', '意见反馈');
		$this->display();
	}

}